package proxy

import (
	"fmt"
	"net/http"
	"net/http/httputil"
	"net/url"
)

func sayHello(w http.ResponseWriter, r *http.Request) {
	u, _ := url.Parse("http://127.0.0.1:9091/proxy")
	proxy := httputil.NewSingleHostReverseProxy(u)
	proxy.ServeHTTP(w, r)
}
func proxyForServer() {
	http.HandleFunc("/topgoer", sayHello)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		fmt.Println("HTTP server failed,err:", err)
		return
	}
}

func proxyClientFmt(w http.ResponseWriter, r *http.Request) {
	sprintf := fmt.Sprintf("topgoer.com是个不错的网站我是9091里面的")
	_, err := w.Write([]byte(sprintf))
	if err != nil {
		fmt.Errorf(err.Error())
		return
	}
}
func proxyCli() {
	http.HandleFunc("/proxy/topgoer", proxyClientFmt)
	err := http.ListenAndServe(":9091", nil)
	if err != nil {
		fmt.Println("HTTP server failed,err:", err)
		return
	}
}
